
#include<stdio.h>

int main()
{
	int n = 0;
	scanf("%d", &n);
	while (1)
	{
		int ret = 0;
		while (n != 0)
		{
			ret += n % 10;
			n /= 10;
		}
		if (ret < 10)
		{
			printf("%d\n", ret);
			break;
		}
		n = ret;
	}
	
	return 0;	
} 

